package com.lagou.bigdata.task01;


/*
    编程统计字符串"ABCD123!@#$%ab"中大写字母、小写字母、数字、其它字符的个数并打 印出来。
*/

public class Demo01 {
    public static void main(String[] args) {

        // 1. 实例化一个字符串对象
        String str = "ABCD123!@#$%ab";


        int upperCharNum = 0;
        int lowerCharNum = 0;
        int digitalCharNum = 0;
        int otherCharNum = 0;

        for (int i=0; i<str.length(); i++) {
            char c = str.charAt(i);
            if ( c >= 65 && c <= 90 ) {
                // System.out.println(c + "-->大写字母");
                upperCharNum += 1;
            } else if (c >= 97 && c <= 122) {
                // System.out.println(c + "-->小写字母");
                lowerCharNum += 1;
            } else if (c >=48 && c<= 57) {
                // System.out.println(c + "-->数字");
                digitalCharNum += 1;
            } else {
                // System.out.println(c + "-->其他字符");
                otherCharNum += 1;
            }
        }

        System.out.println(str);
        System.out.println("大写字母个数:" + upperCharNum + "\n" + "小写字母个数:" + lowerCharNum + "\n" +
                "数字个数:" + digitalCharNum + "\n" + "其它字符个数:" + otherCharNum);
    }
}
